package model.dominio;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.Table;
import model.dao.DaoBase;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "Funcionario") 
public class Funcionario extends Pessoa implements Serializable {

    @Column(length = 60)
    private String cargo;

    public Funcionario() {
    }

    /**
     * @return the cargo
     */
    public String getCargo() {
        return cargo;
    }

    /**
     * @param cargo the cargo to set
     */
    public void setCargo(String cargo) {
        this.cargo = cargo;
    }

    public Funcionario(String nome, String cpf, String cargo) {
        super(nome, cpf);
        this.cargo = cargo;
    }

    public Funcionario(String nome, String cpf, String telefone, String endereco, String cargo) {
        super(nome, cpf, telefone, endereco);
        this.cargo = cargo;
    }

    @Override
    public String toString() {
        return super.toString() + ",<cargo=" + this.cargo + ">";
    }
    @PostPersist
    public void gerarLogCad() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(super.getCodigo());
        logg.setAcao(new AcaoSistema(9));
        logg.setData_hora(super.getData_ultima_alteracao());
        logg.setUsuario(super.getUsuario());
        new DaoBase().salvar(logg);
    }

    @PostUpdate
    public void gerarLogAlt() {
        Logg logg = new Logg();
        logg.setCodigo_objeto(this.getCodigo());
        logg.setAcao(new AcaoSistema(10));
        logg.setData_hora(this.getData_ultima_alteracao());
        logg.setUsuario(this.getUsuario());
        new DaoBase().salvar(logg);
    }
}